#ifndef _KCSTRING_H_
#define _KCSTRING_H_

/*
作    者：		王清
创建时间:			2017-04-30
说    明：		字符串类
*/

/*
王清		2017-04-30	新建文件
王清		2017-09-08	设计KCString类基本结构和接口
王清		2017-09-09	设计KCString接口
*/

namespace kckit{
	
	enum KCEncodeType {
		ASCII	= 0,
		UTF8 	= 1,
		UTF16 	= 2,
		UTF32	= 3,
		GBK		= 4
	};

	class KCString {
	public:

		//ctor & dtor
		KCString();
		KCString(const KCString &str);
		KCString(const std::string str);
		KCString(const char* str);
		KCString(const kckit::KCEncodeType &encodeType);
		~KCString();

		//static funcs
		static int 			toInt(const KCString &str);
		static double 		toDouble(const KCString &str);
		static float 		toFloat(const KCString &str);
		static int 			toNumber(const KCString &str, int base = 10);
		static KCString 	fromIntToKCString(int number);
		static KCString 	fromDoubleToKCString(double number);
		static KCString 	fromFLoatToKCString(int number);
		static KCString 	toBinaryKCString(int number);
		static KCString 	toHexKCString(int number);
		static KCString 	toOctKCString(int number);
		static KCString 	fromStdString(const std::string &str);
		static std::string 	toStdString(const KCString &str);

		//member funcs
		bool 			setEncodeType(KCEncodeType encodeType);
		KCEncodeType 	getEncodeType() const;
		bool 			toASCII();
		bool 			toUTF8();
		bool 			toUTF16();
		bool 			toUTF32();
		bool 			toGBK();
		unsigned 		getLength() const;	
		unsigned 		getFreeLength() const;
		std::string 	toStdString() const;
		char* 			toCStyle() const;
		
		KCString &		append(const KCString &str);
		KCString & 		append(const char *str);
		KCString &  	append(const std::string &str);
		
		KCString & 		prepend(const KCString &str);
		KCString & 		prepend(const char *str);
		KCString &  	prepend(const std::string &str);
		
		
	private:
		void _assign();

	private:
		unsigned 	m_Length;
		unsigned	m_FreeLen;
		char* 		m_Data;

		unsigned	m_RefCount;
	};//KCString class	

}





#endif
